package cn.example.practice.servlet;


import cn.example.practice.db.GoodsDao;
import cn.example.practice.model.Goods;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.List;

@WebServlet("/shopListServlet")
public class ShopListServlet extends HttpServlet {
    private final GoodsDao goodsDao = new GoodsDao();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        List<Goods> goodsList = goodsDao.getAllGoods();
        request.setAttribute("goodsList", goodsList);
        request.getRequestDispatcher("/WEB-INF/jsp/shop_list.jsp").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
